package com.cosmocoder.persistence.jpa;

import java.io.Serializable;

import javax.persistence.EntityManagerFactory;

import com.cosmocoder.persistence.AbstractDaoFactory;
import com.cosmocoder.persistence.Dao;
import com.cosmocoder.persistence.DaoFactory;


public class JpaDaoFactory extends AbstractDaoFactory implements DaoFactory  {
	
	private JpaDaoFactory() {	}
	
	EntityManagerFactory entityManagerFactory;
	public EntityManagerFactory getEntityManagerFactory() {
		return entityManagerFactory;
	}

	
	public void setEntityManagerFactory(EntityManagerFactory entityManagerFactory) {
		this.entityManagerFactory = entityManagerFactory;
	}
	
	protected <EntityType, IdType extends Serializable> Dao<EntityType, IdType> createDao(Class<EntityType> entityClass) {
		JpaDao<EntityType, IdType> dao = new JpaDao<EntityType, IdType>();
		dao.setEntityClass(entityClass);
		dao.setEntityManagerFactory(entityManagerFactory);
		return dao;
	}
}
